package com.lin.ovc.pomodoro.controller;


import com.lin.ovc.pomodoro.entity.Task;
import com.lin.ovc.pomodoro.entity.dto.TaskForm;
import com.lin.ovc.pomodoro.service.TaskService;
import com.lin.ovc.pomodoro.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lin
 * @since 2024-07-25
 */
@RestController
@RequestMapping("/pomodoro/task")
public class TaskController {
    @Autowired
    TaskService taskService;

    //添加任务
    @PostMapping()
    public R addTask(@RequestBody TaskForm form) {
        taskService.save(form);
        return R.ok();
    }

    //更新任务
    @PutMapping()
    public R updateTask(TaskForm form) {
        taskService.update(form);
        return R.ok();
    }

    //通过清单ID获取该清单的所有任务
    @GetMapping()
    public R searchAllTaskOfUser(long id) {
        System.out.println(id);
        List<Task> lists = taskService.list(id);
        return R.ok().data("data",lists);
    }

    //删除指定的任务
    @DeleteMapping()
    public R DeleteTask(long id) {
        if(taskService.removeById(id)) return R.ok();
        else return R.error();
    }

}

